﻿@using Example3.MvcWebApp.IndividualAccounts.PermissionsCode
@using AuthPermissions.AspNetCore.AccessTenantData
@using AuthPermissions.BaseCode.CommonCode
@using AuthPermissions.BaseCode.PermissionsCode
@inject ILinkToTenantDataService LinkToTenantDataService
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - Example3</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
    <header>
        <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
            <div class="container">
                <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Example3</a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                        aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
                    <ul class="navbar-nav flex-grow-1">
                        <li class="nav-item">
                            <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
                        </li>
                        @if (!User.Identity.IsAuthenticated)
                        {
                            <li class="nav-item">
                                <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="CreateTenant">Sign up now!</a>
                            </li>
                        }
                        @if (User.Identity.IsAuthenticated)
                        {
                            @if (User.HasPermission(Example3Permissions.TenantAccessData))
                            {
                                <li class="nav-item">
                                    <a class="nav-link text-dark" asp-area="" asp-controller="Invoice" asp-action="Index">Invoices</a>
                                </li>
                            }
                            <li class="dropdown nav-link text-dark">

                                <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                                    Auth Admin
                                </a>
                                <div class="dropdown-menu">
                                    <a class="dropdown-item" asp-area="" asp-controller="AuthUsers" asp-action="Index">List all AuthUsers</a>
                                    <a class="dropdown-item" asp-area="" asp-controller="Roles" asp-action="Index">List Roles</a>
                                    @if (User.HasPermission(Example3Permissions.TenantList))
                                    {
                                        <a class="dropdown-item" asp-area="" asp-controller="Tenant" asp-action="Index">List Tenants</a>
                                    }
                                    @if (User.HasPermission(Example3Permissions.PermissionRead))
                                    {
                                        <a class="dropdown-item" asp-area="" asp-controller="Roles" asp-action="ListPermissions">List all Permissions</a>
                                    }
                                </div>
                            </li>
                            <li class="dropdown nav-link text-dark">
                                <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                                    Users info
                                </a>
                                <div class="dropdown-menu">
                                    <a class="dropdown-item" asp-area="" asp-controller="LoggedInUser" asp-action="Index">Your claims</a>
                                    <a class="dropdown-item" asp-area="" asp-controller="LoggedInUser" asp-action="AuthUserInfo">Your auth data</a>
                                    <a class="dropdown-item" asp-area="" asp-controller="LoggedInUser" asp-action="UserPermissions">Your Permissions</a>
                                </div>
                            </li>
                        }

                        <li class="nav-item">
                            <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
                        </li>
                        <partial name="_LoginPartial" />
                    </ul>
                </div>
            </div>
        </nav>
    </header>

    <div class="container">
        <main role="main" class="pb-3">
            <div class="text-danger">
                @{
                    var tenantName = LinkToTenantDataService.GetNameOfLinkedTenant();
                    if (tenantName != null)
                    {
                        if (!User.Identity.IsAuthenticated)
                        {
                            <script>window.location.replace("@Url.Action("StopAccess", "Tenant", new { gotoHome = true }) ");</script>
                        }
                        <div>
                            Be careful! You are currently linked to the <strong>@tenantName</strong> tenant's data.
                            <a class="btn btn-outline-primary btn-sm" asp-area="" asp-controller="Tenant" asp-action="StopAccess">Stop Linking</a>
                        </div>
                    }
                }
            </div>
            @RenderBody()
        </main>
    </div>

    <footer class="border-top footer text-muted">
        <div class="container">
            &copy; 2021 - AuthPermission's Example3 - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
        </div>
    </footer>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>
    @await RenderSectionAsync("Scripts", required: false)
</body>
</html>
